<?php

/**
 * 账户信息
 */

namespace app\sale\common;

class InfoCommon extends \app\sale\common\SaleCommon{


    protected function index() {
        $this->setMeta('推广信息');
        $this->pageInfo['name'] = '推广信息';

        $model = target('sale/SaleOrder');


        //本年消费
        $yearList = $model->loadList([
            'A.sale_status' => 2,
            '_sql' => 'A.create_time > ' . strtotime(date("Y", time()) . "-1" . "-1") . ' AND A.create_time <' . strtotime(date("Y", time()) . "-12" . "-31"),

        ]);

        $yearCount = [];
        $yearCount['labels'] = [];
        $yearCount['series'] = [];
        for ($i = 1; $i < 13; $i++) {
            $yearCount['labels'][] = $i . '月';
        }

        $yearCharge = [];
        foreach ($yearList as $vo) {
            $yearCharge[intval(date('m', $vo['create_time']))] += $vo['sale_money'];
        }

        $yearChargeData = [];

        for ($i = 1; $i < 13; $i++) {
            $yearChargeData[] = $yearCharge[$i] ? $yearCharge[$i] : '0';
        }
        $yearCount['series'][] = $yearChargeData;


        $this->assign('yearCountJson', json_encode($yearCount));


        $saleMoneyCount = target('sale/SaleOrder')->query("select sum(sale_money) as cashout from {pre}sale_order where sale_status = 2");
        $saleMoneyCount = $saleMoneyCount[0]['cashout'] ? $saleMoneyCount[0]['cashout'] : 0.00;


        $saleMoneyMonth = target('sale/SaleOrder')->query("select sum(sale_money) as cashout from {pre}sale_order where sale_status = 2 AND create_time > " . mktime(0, 0, 0, date("m", time()), 1, date("Y", time())) . ' AND create_time < ' . mktime(23, 59, 59, date("m", time()), date('t'), date("Y", time())));
        $saleMoneyMonth = $saleMoneyMonth[0]['cashout'] ? $saleMoneyMonth[0]['cashout'] : 0.00;

        $userCount = target('sale/SaleUser')->countList([
            'parent_id' => $this->saleInfo['user_id']
        ]);

        $agentCount = target('sale/SaleUser')->countList([
            'parent_id' => $this->saleInfo['user_id'],
            'agent' => 1
        ]);

        $this->assign('saleInfo', $this->saleInfo);
        $this->assign('userCount', $userCount);
        $this->assign('agentCount', $agentCount);


        $this->assign('saleMoneyCount', $saleMoneyCount);
        $this->assign('saleMoneyMonth', $saleMoneyMonth);
        $this->memberDisplay();
    }

}